package com.ruoyi.web.controller.cabinet;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cabinet.domain.CabGoodsOut;
import com.ruoyi.cabinet.service.ICabGoodsOutService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物品出库Controller
 * 
 * @author ruoyi
 * @date 2024-01-31
 */
@RestController
@RequestMapping("/goods/goodsOut")
public class CabGoodsOutController extends BaseController
{
    @Autowired
    private ICabGoodsOutService cabGoodsOutService;

    /**
     * 查询物品出库列表
     */
    @PreAuthorize("@ss.hasPermi('goods:goodsOut:list')")
    @GetMapping("/list")
    public TableDataInfo list(CabGoodsOut cabGoodsOut)
    {
        startPage();
        List<CabGoodsOut> list = cabGoodsOutService.selectCabGoodsOutList(cabGoodsOut);
        return getDataTable(list);
    }

    /**
     * 导出物品出库列表
     */
    @PreAuthorize("@ss.hasPermi('goods:goodsOut:export')")
    @Log(title = "物品出库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CabGoodsOut cabGoodsOut)
    {
        List<CabGoodsOut> list = cabGoodsOutService.selectCabGoodsOutList(cabGoodsOut);
        ExcelUtil<CabGoodsOut> util = new ExcelUtil<CabGoodsOut>(CabGoodsOut.class);
        util.exportExcel(response, list, "物品出库数据");
    }

    /**
     * 获取物品出库详细信息
     */
    @PreAuthorize("@ss.hasPermi('goods:goodsOut:query')")
    @GetMapping(value = "/{outId}")
    public AjaxResult getInfo(@PathVariable("outId") Long outId)
    {
        return success(cabGoodsOutService.selectCabGoodsOutByOutId(outId));
    }

    /**
     * 新增物品出库
     */
    @PreAuthorize("@ss.hasPermi('goods:goodsOut:add')")
    @Log(title = "物品出库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CabGoodsOut cabGoodsOut)
    {
        return toAjax(cabGoodsOutService.insertCabGoodsOut(cabGoodsOut));
    }

    /**
     * 修改物品出库
     */
    @PreAuthorize("@ss.hasPermi('goods:goodsOut:edit')")
    @Log(title = "物品出库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CabGoodsOut cabGoodsOut)
    {
        return toAjax(cabGoodsOutService.updateCabGoodsOut(cabGoodsOut));
    }

    /**
     * 删除物品出库
     */
    @PreAuthorize("@ss.hasPermi('goods:goodsOut:remove')")
    @Log(title = "物品出库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{outIds}")
    public AjaxResult remove(@PathVariable Long[] outIds)
    {
        return toAjax(cabGoodsOutService.deleteCabGoodsOutByOutIds(outIds));
    }
}
